#ifndef HASPINFO_H
#define HASPINFO_H


#include <stdio.h>
#include <stdlib.h>
#include <QString.h>
#include "hasp.h"           
#include <QVector>
#include <QMap>


typedef struct CONFIG_INFO_51tag
{
	short  Version1;  // Version Major (Bits 15..12 of MODULE_INFO_51.Param1)
	short  Version2;  // Version Minor (Bits 11..8  of MODULE_INFO_51.Param1)
	short  Version3;  // Build         (Bits  7..4  of MODULE_INFO_51.Param1)
	short  Version4;  // Misc. info    (Bits  3..0  of MODULE_INFO_51.Param1)
	short  Value;     // Numeric parameter (MODULE_INFO_51.Param2)
	short  Year;      // Year  (2050 + Bits 15..9 of MODULE_INFO_51.Param3)
	short  Month;     // Month (Bits 8..5 of MODULE_INFO_51.Param3)
	short  Day;       // Day   (Bits 4..0 of MODULE_INFO_51.Param3)
	QString nameOfCell; // Number of cell

} CONFIG_INFO;

class managHaspInfo
{
private:
	// Structs 
	typedef struct MODULE_INFO_51tag
	{
		short Param1;
		short Param2;
		short Param3;
	} MODULE_INFO_51 ;

	typedef struct CONFIG_INFO_51tag
	{
		short  Version1;  // Version Major (Bits 15..12 of MODULE_INFO_51.Param1)
		short  Version2;  // Version Minor (Bits 11..8  of MODULE_INFO_51.Param1)
		short  Version3;  // Build         (Bits  7..4  of MODULE_INFO_51.Param1)
		short  Version4;  // Misc. info    (Bits  3..0  of MODULE_INFO_51.Param1)
		short  Value;     // Numeric parameter (MODULE_INFO_51.Param2)
		short  Year;      // Year  (2050 + Bits 15..9 of MODULE_INFO_51.Param3)
		short  Month;     // Month (Bits 8..5 of MODULE_INFO_51.Param3)
		short  Day;       // Day   (Bits 4..0 of MODULE_INFO_51.Param3)
		QString nameOfCell; // Number of cell

	} CONFIG_INFO_51;

	union cripto
	{
		int h;
		char s[4];
	};

	union readByte
	{
		short h;
		char s[2];
	};

public:
	managHaspInfo();
	~managHaspInfo();

	//return code of error
	int ScanHasp(QMap<int, QString>& listProd);
    
	int sizeBlock70_207();
	void returnBlock70_207(int i, CONFIG_INFO& c);

	int sizeBlock69_0();
	void returnBlock69_0(int i, CONFIG_INFO& c);

	int getHeaspId()
	{
		if (IsHaspOk())
		{
            ReadHaspID(); 
			return haspId;
		}
		else
		{
			return -1;
		}
	};

	//int sizeBlock208_247();
	//CONFIG_INFO_51 *returnBlock208_247(int i);

private:
// Functions
	// test of Hasp 
	bool IsHaspOk();

	// return 0 - hasp Id was taken
	// else code of error
	int  ReadHaspID();

	// decoding functions
	void ReadBlock69_0   (QMap<short,short>& block, QMap<int, QString>& listProd);
	void ReadBlock70_207 (QMap<short,short>& block,QMap<short,short>& extra,QMap<int, QString>& listProd);
	//void ReadBlock208_247(QMap<short,short>& block);

	

// Variables
	//using for decoding V6.0 and V5.1
	int initial;
	int j;
	int haspId;


	int Pass1;  /* the first HASP password  */
	int Pass2;  /* the second HASP password */

	QVector<CONFIG_INFO_51> strInfo207_247;
	QVector<CONFIG_INFO_51> strInfo70_207;
	QVector<CONFIG_INFO_51> strInfo69_0;
	QMap<short,int> virtualAddress;
    

};

#endif 
